package com.example.financeapi;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * @author Alvin
 */
@EnableCaching
@SpringBootApplication
@EnableAsync(proxyTargetClass = true) //aop的代理，使用cglib方式，默认是jdk方式
public class FinanceApiApplication {

	@Value("${http.port}")
	private Integer httpPort;

	@Value("${server.port}")
	private Integer httpsPort;

	public static void main(String[] args) {
		SpringApplication.run(FinanceApiApplication.class, args);
		String strConsole = "\n" +
				"    *           *      \n" +
				" *     *     *     *	\n" +
				" *        *        *   \n" +
				"  *   ZlyFlycat   *	\n" +
				"    *           *   	\n" +
				"       *     *      	\n" +
				"          *    		\n" +
				"  ლ(´ڡ`ლ)ﾞ  sell started successfully!!!  (♥◠‿◠)ﾉﾞ  \n";
		System.out.println(strConsole);
	}

/*	@Bean
	@ConditionalOnProperty(name = "condition.http2https", havingValue = "true", matchIfMissing = false)
	public TomcatServletWebServerFactory servletContainer() {
		TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
			@Override
			protected void postProcessContext(Context context) {
				SecurityConstraint constraint = new SecurityConstraint();
				constraint.setUserConstraint("CONFIDENTIAL");
				SecurityCollection collection = new SecurityCollection();
				collection.addPattern("/*");
				constraint.addCollection(collection);
				context.addConstraint(constraint);
			}
		};
		tomcat.addAdditionalTomcatConnectors(httpConnector());
		return tomcat;
	}

	@Bean
	@ConditionalOnProperty(name = "condition.http2https", havingValue = "true", matchIfMissing = false)
	public Connector httpConnector() {
		System.out.println("启用http转https协议，http端口：" + this.httpPort + "，https端口：" + this.httpsPort);
		Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
		connector.setScheme("http");
		// Connector监听的http的端口号
		connector.setPort(httpPort);
		connector.setSecure(false);
		// 监听到http的端口号后转向到的https的端口号
		connector.setRedirectPort(httpsPort);
		return connector;
	}*/
}
